<?php
	$auth = Zend_Auth::getInstance()->setStorage(new Zend_Auth_Storage_Session('user'));
	$slider = '';
	
	// Quảng cáo ở giữa kế bên search
	if(count($this->adv3) > 0) {
		$slider .= '<div class="slideshow" data-transition="crossfade" data-loop="true" data-skip="false">';
		$slider .= '<ul class="carousel">';
		
		While (list($key, $val) = each($this->adv3)) {
			if ($auth->hasIdentity()) {
				$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point3 .')';
			} else {
				$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
			}

			$slider .= '<li class="slide">';
			$slider .= $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
			$slider .= '</li>';
		}

		$slider .= '</ul>';
		$slider .= "</div>";
		$slider .= '<script type="text/javascript">';
		$slider .= '$(".slideshow").slides({hoverPause: true, speed: 600, autostop: false, auto: 4000});';
		$slider .= '</script>';
	}
	
	$layout = $this->cmsSearch('slider', '36%', $slider); 
	echo $layout;
	$layout = $this->cmsSubmenu(); 
	echo $layout;
	
	// Chi tiết tin
	$info = $this->itemsViewTinTuc;
	$tieu_de 	= $info->tieu_de;
	$ngay_dang 	= $info->ngay_tao;
	$datetime 	= explode(" ", $ngay_dang);
	$luot_xem 	= $info->luot_xem;
	$gioi_thieu	= $info->gioi_thieu;
	$noi_dung 	= $info->noi_dung;
	$hinh_anh 	= $info->hinh_anh;
	
	$frm_sendmailfriend = $this->form_sendmail;
?>
<div id="wrapcontent">
	<?php
		// Quảng cáo ở bên trái
		if(count($this->adv2) > 0) {
			echo "<div id='floating_banner_left'>";
			
			While (list($key, $val) = each($this->adv2)) {
				if ($auth->hasIdentity()) {
					$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point2 .')';
				} else {
					$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
				}
					
				echo $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
			}
			
			echo "</div>";
		}
	?>
	<div id="sidebar1">
		<?php
			$img = '<img src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/icon_hot.gif") . '" />';
			$block = $this->cmsBlock('Phòng trọ', $img, $this->itemsHotPtrTinTro); 
			echo $block;
			
			// Logo ở bên trái
			if(count($this->adv5) > 0) {
				echo "<div>";
					
				While (list($key, $val) = each($this->adv5)) {
					if ($auth->hasIdentity()) {
						$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point5 .')';
					} else {
						$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
					}
			
					echo $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
				}
					
				echo "</div>";
			}
		?>
		<!-- Begin Block hỗ trợ trực tuyến -->
		<?php 
			$block = $this->cmsBlock('Hỗ trợ trực tuyến', '', $this->thong_tin_cty, 3); 
			echo $block;
		?>
		<!-- End Block hỗ trợ trực tuyến -->
		<!-- Begin Block thống kê truy cập -->
		<?php 
			$block = $this->cmsBlock('Thống kê truy cập', '', 'info', 4); 
			echo $block;
		?>
		<!-- End Block thống kê truy cập -->
		<br class="clear" />
	</div>
	<?php
		// Quảng cáo ở bên phải
		if(count($this->adv4) > 0) {
			echo "<div id='floating_banner_right'>";
		
			While (list($key, $val) = each($this->adv4)) {
				if ($auth->hasIdentity()) {
					$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point4 .')';
				} else {
					$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
				}
					
				echo $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
			}
		
			echo "</div>";
		}
	?>
	<div id="sidebar2">
		<div class="block">
			<div class="title">
				<span>Mạng xã hội</span>
			</div>
			<div class="content">
				<div class="follow">
					<div class="addthis_toolbox addthis_32x32_style addthis_vertical_style">
						<a class="addthis_button_facebook_follow" addthis:userid="kenhnhatro.vn"></a>
						<a class="addthis_button_twitter_follow" addthis:userid="kenh_nhatro"></a>
					</div>
				</div>
			</div>
			<br class="clear" />
		</div>
		<?php
			$img = '<img src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/icon_new.gif") . '" />';
			$block = $this->cmsBlock('Tin rao mới', $img, $this->itemsNewPtrTinTro); 
			echo $block;
			$img = '<img class="icon" src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/highlights.png") . '" />';
			$block = $this->cmsBlock('Tin tức nổi bật', $img, $this->itemsHotTinTuc, 2);
			echo $block;
			
			// Logo ở bên phải
			if(count($this->adv6) > 0) {
				echo "<div>";
					
				While (list($key, $val) = each($this->adv6)) {
					if ($auth->hasIdentity()) {
						$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point6 .')';
					} else {
						$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
					}
			
					echo $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
				}
					
				echo "</div>";
			}
		?>
	</div>
	<div id="primary">
		<div class="block">
			<div class="title">
				<div class="icon-arrow"></div>
				<span>Tin tức phòng trọ</span>
			</div>
			<div class="content">
				<p class="tieu-de"><?php echo $tieu_de; ?></p>
				<div class="meta">
					<span class="datetime"><?php echo $datetime[1]; ?> <font class="date"><?php echo $datetime[0]; ?></font></span>
					<!-- AddThis Button BEGIN -->
					<div class="addthis_toolbox addthis_default_style add-button">
						<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
						<a class="addthis_button_tweet"></a>
						<a class="addthis_button_pinterest_pinit"></a>
						<a class="addthis_counter addthis_pill_style"></a>
					</div>
					<!-- AddThis Button END -->
				</div>
				<div class="view-info">
					<div class="description-item"><?php echo $gioi_thieu; ?></div>
					<div class="content-item"><?php echo $noi_dung; ?></div>
					<div class="toolbar">
						<ul>
							<li><a class="back" href="#" onclick="history.go(-1)">Quay lại</a></li>
							<li><a class="forward" href="#sendFriendModal" data-toggle="modal">Gửi cho bạn bè</a></li>
						</ul>
					</div>
					<div class="clear"></div>
				</div>
			</div>
		</div>
	</div>
	<!-- SEND MAIL FOR FRIEND MODAL -->
	<div id="sendFriendModal" class="modal hide fade" tabindex="-1"
		role="dialog" aria-labelledby="sendFriendModalLabel" aria-hidden="true">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal"
				aria-hidden="true">×</button>
			<h3 id="sendFriendModalLabel">Gửi cho bạn bè tin này</h3>
		</div>
		<div class="modal-body">
			<div id="sendfriendalert" class="alert"></div>
			<form class="form-horizontal">
				<?php echo $frm_sendmailfriend->link_bai_viet;?>
				<div class="control-group">
					<label class="control-label" for="ten_nguoi_gui">Tên của bạn</label>
					<div class="controls">
					<?php echo $frm_sendmailfriend->ten_nguoi_gui;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="email_from">Email của bạn</label>
					<div class="controls">
					<?php echo $frm_sendmailfriend->email_from;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="email_to">Gửi đến (To)</label>
					<div class="controls">
					<?php echo $frm_sendmailfriend->email_to;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="tieu_de">Tiêu đề (Subject)</label>
					<div class="controls">
					<?php echo $frm_sendmailfriend->tieu_de;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="thong_diep">Thông điệp (Message)</label>
					<div class="controls">
						<?php echo $frm_sendmailfriend->thong_diep;?>
					</div>
				</div>
			</form>
		</div>
		<div class="modal-footer">
			<button class="btn" data-dismiss="modal" aria-hidden="true">Bỏ qua</button>
			<button id="btnSendFriend" class="btn btn-primary">Gửi</button>
		</div>
	</div>
	<script type="text/javascript">
		//Catch keydown event of the enter key
		$('#sendFriendModal').keydown(function (e){
			if(e.keyCode == 13){
				sendForFriendProcess(e);
			}
		});
		//Catch click event of the login button
		$('#btnSendFriend').click(function(e) {
			sendForFriendProcess(e);
		});
		
		$('#forward').click(function() {
			$('#sendfriendalert').hide();
		});
		
		//Show the modal event processing
		$('#sendFriendModal').on('show', function () {
			$(this).find('.alert').hide();
			$(this).find("input").each(function() {
				var inputid = $(this).attr('id');
				$("#"+inputid).parent().find('.errors').remove();
				$("#"+inputid+'[type="text"]').val("");
		    });
			$(this).find("textarea").each(function() {
				var inputid = $(this).attr('id');
				$("#"+inputid).val("");
		    });
		});
		
		$(function(){
			$('#sendFriendModal').find("input").each(function() {
		        var inputid = $(this).attr('id');
		        $("#"+inputid).blur(function() {
		        	if(doValidation('sendFriendModal', inputid,'/ajax/validateforward',null))
		        		$("#btnSendFriend").removeAttr("disabled");
		        	else
		        		$("#btnSendFriend").attr("disabled", "disabled");	
		        });
		    });
		});
		//Process login function
		function sendForFriendProcess(event) {
			var url = '/ajax/sendforfriend';
			var $this = $(this);
			var postData = $("#sendFriendModal form").serializeObject();
			postData.format = "json";
			var isValid = true;
			$('#sendFriendModal').find("input").each(function() {
				var inputid = $(this).attr('id');
				isValid = isValid&&doValidation('sendFriendModal', inputid, '/ajax/validateforward', 'validate');
		    });
			if(isValid){
				$("#btnSendFriend").attr("disabled", "disabled");
				$.ajax({
		            type: 'POST',
		            url: url,
		            async: true,
		            cache: true,
		            data: postData,
		            dataType: postData.format,
		            success: function(data){
		            	if(data.result) {
	                		$('#sendfriendalert').html(data.message);
	                		$('#sendfriendalert').show();
		            		setTimeout(function() {
								$('#sendFriendModal').modal('hide'); 
							}, 1000);
		            	} else {
		            		if(data.message){
		                		$('#sendfriendalert').html(data.message);
		                		$('#sendfriendalert').show();
		                    }
		                }
		            }
		        });
				$("#btnSendFriend").removeAttr("disabled");
			}
		}
	</script>
   	<div class="clear"></div>
</div>